home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / net3d-0.08 / command.c < prev    next >
C/C++ Source or Header  |  1995-06-22  |  1KB  |  56 lines

  1. /* command.c
  2.  *
  3.  * functions used by server to communicate with client
  4.  */
  5.  
  6. #include "net3d.h"
  7.  
  8. int stillalive;
  9.  
  10. /* Read a line from each client, and re-transmit them to all clients
  11.  */
  12. void processnet(int psocks[], int plcount, int mainsock)
  13. {
  14. char clcom[400];            /* message to send to clients */
  15. char *msg;                /* message from client */
  16. static Bool dead[MAX_PLAYERS] = {0};    /* list of who's dead */
  17. int i;                    /* loop counter */
  18.  
  19. /* start broadcast with game time, followed by concatenation of 
  20.  * messages from clients.
  21.  */
  22. sprintf(clcom,"%f",gametime());
  23. for(i=0; i<plcount; i++) {
  24.     msg=ngets(psocks[i]);
  25. #if NETDEBUG
  26.         printf("recieved \"%s\" from player %d\n",msg,i);
  27. #endif
  28.     if (msg[0] == 'd' && !dead[i]) {
  29.         /* client has declared that it's player is dead.
  30.          */
  31.         dead[i] = True;
  32.         stillalive--;
  33.         if (stillalive==1) {
  34.             /* Tell all clients that only one player is left. */ 
  35.             strcat(clcom," w 0 0.0");
  36.             printf("we have a winner..\n");
  37.             }
  38.         }
  39.     else {
  40.         if (strlen(msg)) {
  41.             strcat(clcom," ");
  42.             strcat(clcom,msg);
  43.             }
  44.         }
  45.     }
  46.  
  47. /* send broadcast message to all clients */
  48. #if NETDEBUG
  49.     printf("sending \"%s\" to clients\n",clcom);
  50. #endif
  51.  
  52. for(i=0; i<plcount; i++)
  53.     nprintf(psocks[i],"%s\n",clcom);
  54. }
  55.  
  56.